﻿/*
 * RenderStyle
 * 
 * initial implementation : 20.10.2008
 *
 * Copyright (c) Adam Sida, asida@centrum.cz.
 * All rights reserved.
 * 
 * for license see Petra.Gis.License.txt
 */
using System;
using System.Collections.Generic;
//using System.Xml.Serialization;

namespace Petra.Gis.RenderingServices.PlanarBase 
{

  /// <summary>
  /// holds all informations about display style for draw/display geometry through renderer.
  /// Some style items can be outputFormat specific but major is common to <c>PlanarMap</c>s
  /// </summary>
  public class RenderStyle
  {



    /// <summary>
    /// xaml constructor
    /// </summary>
    public RenderStyle()
    {
      _styleComponents = new StyleComponents();
    }




    //protected StyleScaleType _styleScaleType;

    public StyleScaleTypeEnum StyleScaleType
    { get; set; }





    //protected bool _enabled = true;

    /// <summary>
    /// runtime property determines if this style is drawn to map (visible) or not
    /// </summary>
    public bool Enabled
    { get; set; }





    //protected StyleScaleRange _styleScaleRange;


    public DisplayScaleRange DisplayScaleRange
    { get; set; }

    



    public object this[string itemName]
    {
      get{return _styleComponents[itemName];}
    }





    private StyleComponents _styleComponents;

    /// <summary>
    /// dictionary of particular style components.
    /// eg. Color, LineWidth, FillColor,...
    /// </summary>
    public StyleComponents StyleComponents
    {
      get { return _styleComponents; }
      set
      {
        if (value == null)
          throw new ArgumentException("Components null");

        _styleComponents = value;
      }
    }





    /// <summary>
    /// indicates whether style contains
    /// some components that needs attribute field
    /// (non geometry) value from data source
    /// </summary>
    /// <returns></returns>
    public virtual bool HasVisualAttributes
    {
      get
      {
        return this.VisualAttributes.Count > 0;
      }
    }





    private VisualAttributes _visualAttrCache;

    /// <summary>
    /// returns list of names of attributes that must be returned from data source
    /// to draw this style
    /// </summary>
    public VisualAttributes VisualAttributes
    {
      get 
      {
        if (_visualAttrCache == null)
        {
          _visualAttrCache = new VisualAttributes();
          foreach (KeyValuePair<string, object> kvp in _styleComponents)
            if (kvp.Value is SmartStyleComponent)
              _visualAttrCache.Add(((SmartStyleComponent)kvp.Value).SourceAttributeName);
        }

        return _visualAttrCache; 
      
      }
    }




  }

}
